//
//  IntExt.swift
//  kano
//
//  Created by Frank on 2024/9/30.
//

import Foundation

extension Int {
    //thousandth separator
    func separatorString() -> String {
        let formatter = NumberFormatter()
        formatter.numberStyle = .decimal
        formatter.groupingSeparator = ","
        formatter.minimumFractionDigits = 0
        formatter.maximumFractionDigits = 0

        if let formattedNumber = formatter.string(from: self as NSNumber) {
            print(formattedNumber)
            return formattedNumber
        }
        return ""
    }
    
    static func commaStringToInt(_ string: String) -> Int? {
        let formatter = NumberFormatter()
        formatter.numberStyle = .decimal

        if let number = formatter.number(from: string) {
            return number.intValue
        } else {
            return nil
        }
    }
}
